package com.ziroom.finance.rabbitmq.common.util;


import com.ziroom.finance.rabbitmq.common.base.BaseEntity;
import com.ziroom.finance.rabbitmq.common.base.PageHolder;

/**
 * 分页控制类
 * Created by duxiaokang on 2016/11/2.
 */
public class PageThreadLocal {

    private static ThreadLocal<PageHolder> tl = new ThreadLocal<PageHolder>();

    /**
     * 开启分页
     * @author duxiaokang
     * @param beginRow  开始行数
     * @param pageSize  页面大小
     */
    public static void startPage(int beginRow, int pageSize) {
        tl.set(new PageHolder(beginRow, pageSize));
    }

    /**
     * 关闭分页
     * @author duxiaokang
     */
    public static void clear() {
        tl.remove();
    }

    /**
     * 未查询条件设置分页参数
     * @author duxiaokang
     * @param record    查询的对象
     */
    public static void setParameters(BaseEntity record) {
        PageHolder page = tl.get();
        int beginRow = page.getBeginRow();
        int pageSize = page.getPageSize();
        record.setBeginRow(beginRow);
        record.setPageSize(pageSize);
    }
}
